package com.yanqu.road.server.cmd.newmonopolymkt;

import com.yanqu.road.entity.enums.eMonopolyMarketResType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.newmonopolymkt.NewMonopolyMarketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.newmonopolymkt.NewMonopolyMarketModule;
import com.yanqu.road.server.manger.NewMonopolyMarketCommonMgr;
import com.yanqu.road.server.manger.systemgroup.newmonopolymarket.NewMonopolyMarketMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_NEW_MONOPOLY_MARKET_GET_TEAM, desc = "查看 队伍")
public class NewMonopolyMarketGetTeamInfoCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        NewMonopolyMarketProto.NewMonopolyMarketGetTeamReqMsg req = NewMonopolyMarketProto.NewMonopolyMarketGetTeamReqMsg.parseFrom(packet.getBytes());
        NewMonopolyMarketProto.NewMonopolyMarketGetTeamRespMsg.Builder builder = NewMonopolyMarketProto.NewMonopolyMarketGetTeamRespMsg.newBuilder();
        if(!NewMonopolyMarketMgr.canEnterSystem(player)){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }
        if(req.getType() == eMonopolyMarketResType.OFFICE_NEW.getValue()){
            //周日22点直接限制不让查看
            if(!NewMonopolyMarketMgr.isSystemOpenTime(eMonopolyMarketResType.OFFICE_NEW.getValue())){
                ret = GameErrorCode.E_MONOPOLY_MARKET_SYSTEM_NO_OPEN;
                return;
            }
            NewMonopolyMarketModule marketModule = player.getModule(NewMonopolyMarketModule.class);
            //这边是否可以判断重置，在线同时时周日22点，跨服结算未下发，可能就提前结算了
            NewMonopolyMarketMgr.refreshUser(player,true,false);
            builder.setUserData(NewMonopolyMarketMgr.builderMonopolyMarketUserEntity(marketModule));
            builder.setRet(0);
            player.sendPacket(ClientProtocol.U_NEW_MONOPOLY_MARKET_GET_TEAM, builder);
        }else {
            // 王宫 王帐
            if(!NewMonopolyMarketCommonMgr.isSystemOpenTime(req.getType())){
                builder.setRet(0);
                player.sendPacket(ClientProtocol.U_NEW_MONOPOLY_MARKET_GET_TEAM, builder);
            }else {
                NewMonopolyMarketMgr.sendAppointActivityPacket(player.getUserId(), CrossProtocol.C_CROSS_NEW_MONOPOLY_MARKET_GET_TEAM, req.toBuilder());
            }
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            NewMonopolyMarketProto.NewMonopolyMarketGetTeamRespMsg.Builder builder = NewMonopolyMarketProto.NewMonopolyMarketGetTeamRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_NEW_MONOPOLY_MARKET_GET_TEAM, builder);
        }
    }

}
